﻿using System;
using System.Collections;
using System.Collections.Generic;
using CalcSharp.Core.Containers;
using CalcSharp.Core.Plugin;

namespace plug_mtrximage
{
    class PlugMtrxUnique: ICMDPlugin
    {
        IPluginHost host;
        public Tresult Run(ArrayList parameters)
        {
            string mname = Convert.ToString(parameters[0]);
            AMatrix m = host.Mtrx_mem[mname];
            Tresult res = new Tresult();
            Dictionary<double, byte> unique = new Dictionary<double, byte>();

            for (int i = 0; i < m.Rows; i++)
            {
                for (int j = 0; j < m.Columns; j++)
                {
                    if (!unique.ContainsKey(m[i,j])) unique.Add(m[i, j], 1);
                }
            }
            res.floatingpt = unique.Keys.Count;
            unique.Clear();
            unique = null;
            return res;
        }

        public string Name
        {
            get { return "MTRX_UNIQUE"; }
        }

        public Dictionary<string, string> autocomplete
        {
            get { return null; }
        }

        public string Help
        {
            get { throw new NotImplementedException(); }
        }

        public IPluginHost Host
        {
            get
            {
                return host;
            }
            set
            {
                this.host = value;
                this.host.Register(this);
            }
        }
    }
}
